#include "friendmanager.h"
#include "appchat/accountmanager.h"
#include "network/networkmanager.h"

#include <QDebug>


namespace Friend{

Manager* Manager::m_instance = NULL;

Manager::Manager(QObject *parent) :
    QObject(parent)
{
}

Manager* Manager::instance(QObject *parent)
{

    if (m_instance == NULL)
        m_instance = new Manager(parent);
    return m_instance;
}

void Manager::addFriendRequest(const QString& username, const QString&message)
{
    AddFriendRequest* m_addFriendRequest = new AddFriendRequest(username,message, Network::Manager::instance()->sessionKey() );
    connect(m_addFriendRequest,&AddFriendRequest::responded, this, &Manager::onAddFriendRequestResponse);
    Network::Manager::instance()->post(m_addFriendRequest);
}

void Manager::onAddFriendRequestResponse(Network::HttpRequest *request)
{
    qDebug() << "Manager::onAddFriendRequestResponse" ;
    const Network::HttpRequest &constRequest = *request;
    const Network::Response &response = constRequest.response();
    const AddFriendResponse &addfresponse = (const AddFriendResponse &)response;
    emit responseCodeAddFriendRequest(addfresponse.errorResponsed());

    delete request;
    request = 0;
}


}
